﻿namespace Anley.DomainDrivenDesign.Contract.Domain;

/// <summary>
/// 实体类
/// </summary>
/// <typeparam name="TKey"></typeparam>
public abstract class Entity<TKey>
    : IEntity<TKey>
    where TKey : struct
{
    // 主键
    public abstract TKey Id { get; protected set; }
}

/// <summary>
/// 实体类
/// </summary>
public abstract class Entity
    : Entity<int>, IEntity
{
}

/// <summary>
/// 可创建实体类
/// </summary>
public abstract class CreatableEntity<TKey>
    : Entity<TKey>, ICreatableEntity<TKey>
    where TKey : struct
{
    protected CreatableEntity()
    {
        Creater = string.Empty;
    }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedTime { get; protected set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string Creater { get; protected set; }

    /// <summary>
    /// 设置创建人
    /// </summary>
    /// <param name="createdTime"></param>
    /// <param name="creater"></param>
    public void SetCreater(
        DateTime createdTime,
        string creater)
    {
        CreatedTime = createdTime;
        Creater = creater;
    }
}

/// <summary>
/// 可创建实体类
/// </summary>
public abstract class CreatableEntity
    : CreatableEntity<int>, ICreatableEntity
{
}

/// <summary>
/// 可更新实体类
/// </summary>
/// <typeparam name="TKey"></typeparam>
public abstract class UpdatableEntity<TKey>
    : CreatableEntity<TKey>, IUpdatableEntity<TKey>
    where TKey : struct
{
    protected UpdatableEntity()
    {
        Updater = string.Empty;
    }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedTime { get; protected set; }

    /// <summary>
    /// 更新人
    /// </summary>
    public string? Updater { get; protected set; }

    /// <summary>
    /// 设置更新人
    /// </summary>
    /// <param name="updatedTime"></param>
    /// <param name="updater"></param>
    protected void SetUpdater(
        DateTime? updatedTime,
        string? updater)
    {
        UpdatedTime = updatedTime;
        Updater = updater;
    }
}

/// <summary>
/// 可更新实体类
/// </summary>
public abstract class UpdatableEntity
    : UpdatableEntity<int>, IUpdatableEntity
{
}

/// <summary>
/// 可删除实体类
/// </summary>
/// <typeparam name="TKey"></typeparam>
public abstract class DeletableEntity<TKey>
    : UpdatableEntity<TKey>, IDeletableEntity<TKey>
    where TKey : struct
{
    protected DeletableEntity()
    {
        IsDeleted = false;
    }

    /// <summary>
    /// 是否已删除
    /// </summary>
    public bool IsDeleted { get; protected set; }

    /// <summary>
    /// 删除时间
    /// </summary>
    public DateTime? DeletedTime { get; protected set; }

    /// <summary>
    /// 删除人
    /// </summary>
    public string? Deleter { get; protected set; }

    /// <summary>
    /// 设置删除人
    /// </summary>
    /// <param name="deletedTime"></param>
    /// <param name="deleter"></param>
    protected void SetDeleter(
        DateTime? deletedTime,
        string? deleter)
    {
        IsDeleted = true;
        DeletedTime = deletedTime;
        Deleter = deleter;
    }
}

/// <summary>
/// 可删除实体类
/// </summary>
public abstract class DeletableEntity
    : DeletableEntity<int>, IDeletableEntity
{
}